package netflow.meshGenerator;

import java.io.FileNotFoundException;
import java.io.PrintStream;

import netflow.GraphInput;
import netflow.PreflowPush;
import netflow.SimpleGraph;

/**
 * This class will test network flow algorithms on mesh graphs.
 * 
 * @author William Kim
 * 
 */
public class MeshExperiment
{
  /**
   * Generates the Mesh Graphs that will be used as inputs to our experiment. [#
   * of rows] [# of columns][capacity or maximum capacity][filename][-cc flag]
   */
  public static void generateGraphs()
  {

    for (int i = 0; i <= 100; i += 10)
    {
      // Set the Capacity to a constant high number and vary the shape of the
      // mesh to rectangular up to square (i.e. 10x100 to 100x100)
      String[] args = { "100", String.valueOf(i), "100",
          "src/netflow/meshGenerator/testRowColumn/column" + String.valueOf(i) + ".txt" };
      MeshGenerator mg = new MeshGenerator(args);
      mg.generate();

      // Used the Capacity as the control variable and kept # of rows and # of
      // columns constant
      String[] args2 = { "50", "50", String.valueOf(i + 1),
          "src/netflow/meshGenerator/testCapacity/capacity" + String.valueOf(i + 1) + ".txt" };
      MeshGenerator mg2 = new MeshGenerator(args2);
      mg2.generate();
    }

  }

  public static void main(String args[])
  {
    // generateGraphs();
    
    PrintStream out_columns = null, out_capacity = null;
    try
    {
      out_columns = new PrintStream("src/netflow/meshGenerator/results_columnsPP.txt");
      out_capacity = new PrintStream("src/netflow/meshGenerator/results_capacityPP.txt");
    } catch (FileNotFoundException e)
    {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    out_columns.println("Number of columns, Max Flow, Completion Time");
    out_capacity.println("Capacity, Max Flow, Completion Time");
    for (int i = 0; i <= 100; i += 10)
    {
      SimpleGraph g1 = new SimpleGraph();
      GraphInput.LoadSimpleGraph(g1,
          "src/netflow/meshGenerator/testRowColumn/column" + String.valueOf(i) + ".txt");

      long startTime = System.currentTimeMillis();
      PreflowPush pfp = new PreflowPush(g1);
      int maxFlow = pfp.maxFlow();
      long endTime = System.currentTimeMillis();

      long totalTime = endTime - startTime;
      out_columns.println(String.valueOf(i) + ", " + maxFlow +", " + totalTime);
      
      SimpleGraph g2 = new SimpleGraph();
      GraphInput.LoadSimpleGraph(g2,
          "src/netflow/meshGenerator/testCapacity/capacity" + String.valueOf(i+1) + ".txt");

      startTime = System.currentTimeMillis();
      PreflowPush pfp2 = new PreflowPush(g2);
      maxFlow = pfp2.maxFlow();
      endTime = System.currentTimeMillis();

      totalTime = endTime - startTime;
      out_capacity.println(String.valueOf(i+1) + ", " + maxFlow +", " + totalTime);
    }
  }
}
